package com.soft.base.exception;

import lombok.Getter;

/**
 * 业务拒绝处理异常
 * <p>
 * 业务拒绝异常包括：
 * 1. 用户访问了未授权的数据
 * <p>
 * 这个类会直接以异常的形式处理，前端会返回403，同时错误会记录日志
 * @author user
 */
public class BizForbiddenException extends RuntimeException {
    @Getter
    private boolean ignoreLog = false;

    public BizForbiddenException(String message, boolean ignoreLog) {
        super(message);
        this.ignoreLog = ignoreLog;
    }

    public BizForbiddenException(String message) {
        super(message);
    }

    public static void throwException(String message) {
        throw new BizForbiddenException(message);
    }

    public static void throwExceptionIgnoreLog(String message) {
        throw new BizForbiddenException(message, true);
    }

    public static void throwIf(String message, Boolean throwEnable) {
        if (throwEnable) {
            throw new BizForbiddenException(message, true);
        }
    }
}
